

#include <Font.h>


Font::Font()
{
	base = glGenLists(96);
}

GLvoid Font::BuildFont(HDC inHDC)
{
	mHDC = inHDC;
	mFont = CreateFont(	-14,							// Height Of Font
						0,								// Width Of Font
						0,								// Angle Of Escapement
						0,								// Orientation Angle
						FW_BOLD,						// Font Weight
						FALSE,							// Italic
						FALSE,							// Underline
						FALSE,							// Strikeout
						ANSI_CHARSET,					// Character Set Identifier
						OUT_TT_PRECIS,					// Output Precision
						CLIP_DEFAULT_PRECIS,			// Clipping Precision
						ANTIALIASED_QUALITY,			// Output Quality
						FF_DONTCARE|DEFAULT_PITCH,		// Family And Pitch
						"Courier New");					// Font Name

	mOldFont = (HFONT)SelectObject(mHDC, mFont);
	wglUseFontBitmaps(mHDC, 32, 96, base);				// Builds 96 Characters Starting At Character 32
	SelectObject(mHDC, mOldFont);							// Selects The Font We Want
	DeleteObject(mFont);									// Delete The Font
}

GLvoid Font::Print(float x, float y)
{
	glColor3f(0.0f,1.0f,0.0f);
	// Position The Text On The Screen
	float x1 = -0.45f+0.05f*float(cos(cnt1));
	float y1 = 0.32f*float(sin(cnt2));
	glRasterPos2f(-1.55f,y1);
 	//glRasterPos2f(10,100);
	cnt1+=0.051f;										// Increase The First Counter
	cnt2+=0.005f;
	SetText("Active OpenGL Text With NeHe -  %7.2f    ", y1);	// Print GL Text To The Screen
}

GLvoid Font::SetText(const char *fmt, ...)					// Custom GL "Print" Routine
{
	char		text[256];								// Holds Our String
	va_list		ap;										// Pointer To List Of Arguments

	if (fmt == NULL)									// If There's No Text
		return;											// Do Nothing

	va_start(ap, fmt);									// Parses The String For Variables
	    vsprintf(text, fmt, ap);						// And Converts Symbols To Actual Numbers
	va_end(ap);											// Results Are Stored In Text

	glPushAttrib(GL_LIST_BIT);							// Pushes The Display List Bits
	glListBase(base - 32);								// Sets The Base Character to 32
	glCallLists(strlen(text), GL_UNSIGNED_BYTE, text);	// Draws The Display List Text
	glPopAttrib();										// Pops The Display List Bits
}

Font::~Font()
{
	glDeleteLists(base, 96);
}